package buco.integrity.communication;

import java.util.*;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import buco.core.api.*;

public class ConnectionsConstraint extends SemanticConstraint {

	HashSet<String> bundleNames; 
	
	public ConnectionsConstraint() {
		bundleNames = new HashSet<String>(); 
	}
	
	public boolean isBundleConnected(String bundle) { 
		return bundleNames.contains(bundle); 
	}
	
	public int numberOfConnections() { 
		return bundleNames.size(); 
	}
	
	@Override
	protected void deserialize(JSONObject jsonObject) throws Exception {
		JSONArray arr = (JSONArray) jsonObject.get("bundles");
		for(int i=0; i < arr.size(); i++) { 
			bundleNames.add(arr.get(i).toString()); 
		}		
	}

}
